package com.leo.lime.music.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.support.v4.app.Fragment;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;
import android.widget.Switch;

import com.leo.lime.music.R;
import com.leo.lime.music.view.DrawableTextView;

/**
 * Created by android on 18-8-9.
 */

/**
 * Created For Left Drawer Viewer
 */
public class DrawerFragment extends Fragment {
    private static final String TAG = "DrawerFragment";

    private RelativeLayout mMessageCenterRl;
    private RelativeLayout mSkinCenterRl;
    private RelativeLayout mVIPCenterRl;
    private RelativeLayout mFlowPackageRl;
    private RelativeLayout mPersonalCloudPanRl;

    private RelativeLayout mTimedOffRl;
    private RelativeLayout mSoundEffectRl;
    private RelativeLayout mRecordForRecogRl;
    private RelativeLayout mMusicToolsRl;
    private RelativeLayout mMusicRingRl;

    private RelativeLayout mLyricsDesktopRl;
    private RelativeLayout mLyricsScreenlockRl;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.main_drawer, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        setViewVisibility(
                view,
                R.id.message_center,
                R.string.main_drawer_item_message_center,
                R.drawable.ic_message_line,
                false,
                false,
                null,
                false,
                0
        );
        setViewVisibility(
                view,
                R.id.skin_center,
                R.string.main_drawer_item_skin_center,
                R.drawable.ic_skin,
                false,
                false,
                null,
                false,
                0
        );
        setViewVisibility(
                view,
                R.id.vip_center,
                R.string.main_drawer_item_vip_center,
                R.drawable.ic_vip,
                false,
                false,
                null,
                false,
                0
        );
        setViewVisibility(
                view,
                R.id.flow_package,
                R.string.main_drawer_item_flow_package,
                R.drawable.ic_packages,
                false,
                false,
                null,
                false,
                0
        );
        setViewVisibility(
                view,
                R.id.personal_cloud_pan,
                R.string.main_drawer_item_personal_cloud_pan,
                R.drawable.ic_cloud_pan,
                false,
                false,
                null,
                false,
                0
        );
        setViewVisibility(
                view,
                R.id.timed_off,
                R.string.main_drawer_item_timed_off,
                R.drawable.ic_timed_off,
                false,
                false,
                null,
                false,
                0
        );
        setViewVisibility(
                view,
                R.id.sound_effect,
                R.string.main_drawer_item_sound_effect,
                R.drawable.ic_timed_off,
                false,
                false,
                null,
                false,
                0
        );
        setViewVisibility(
                view,
                R.id.record_for_recog,
                R.string.main_drawer_item_record_for_recog,
                R.drawable.ic_record,
                false,
                false,
                null,
                false,
                0
        );
        setViewVisibility(
                view,
                R.id.music_tools,
                R.string.main_drawer_item_music_tools,
                R.drawable.ic_tools,
                false,
                false,
                null,
                false,
                0
        );
        setViewVisibility(
                view,
                R.id.music_ring,
                R.string.main_drawer_item_music_ring,
                R.drawable.ic_ring,
                false,
                false,
                null,
                false,
                0
        );

        setViewVisibility(
                view,
                R.id.lyrics_desktop,
                R.string.main_drawer_item_lysics_desktop,
                R.drawable.ic_desk_lyrics,
                true,
                false,
                null,
                false,
                0
        );
        setViewVisibility(
                view,
                R.id.lyrics_screenlock,
                R.string.main_drawer_item_lysics_screenlock,
                R.drawable.ic_desk_lyrics,
                true,
                false,
                null,
                false,
                0
        );
    }

    private void setViewVisibility(View view, int parentId, int strId, int drawableId,
                                   boolean showRightFrame, boolean showText, String text, boolean showDrawable, int rDrawId) {
        View parent = view.findViewById(parentId);
        DrawableTextView contentTv = (DrawableTextView) parent.findViewById(R.id.menu_title_tv);
        contentTv.setText(strId);
        contentTv.setDrawable(drawableId);
        if (showRightFrame) {
            DrawableTextView rightTextV = (DrawableTextView) parent.findViewById(R.id.menu_apply_tv);
            Switch switchFrame = (Switch) parent.findViewById(R.id.menu_apply_switch);
            if (showText) {
                rightTextV.setText(text);
                if (showDrawable) {
                    if (rDrawId != 0) {
                        rightTextV.setDrawable(rDrawId);
                    }
                }
                switchFrame.setVisibility(View.GONE);
            } else {
                rightTextV.setVisibility(View.GONE);
                switchFrame.setOnCheckedChangeListener(mSwitchCheckedChangedListener);
                return;
            }
        } else {
            View rightFrame = parent.findViewById(R.id.menu_apply);
            rightFrame.setVisibility(View.GONE);
        }
        parent.setOnClickListener(mDrawerItemClickListener);
    }

    private Switch.OnCheckedChangeListener mSwitchCheckedChangedListener = new Switch.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

        }
    };

    private View.OnClickListener mDrawerItemClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    };
}
